package com.hpf.springcloud.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @description: 提供消息服务实现,@EnableBinding 绑定通道
 * @datetime: 2020/10/25 14:08
 * @author: huangpengfei
 */
@EnableBinding(Source.class)
@Slf4j
public class MessageServiceImpl implements IMessageService {

    /**
     * 消息发送管道，注入ioc
     */
    @Resource
    private MessageChannel output;

    @Override
    public String send() {
        String uuid = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(uuid).build());
        log.info("发送消息内容：{}",uuid);
        return null;
    }
}
